(旧Siv3D) 図形のモーフィング
https://gyazo.com/44659b5ade37ecf14814107a2c7bce4d
code:morph.cpp
void Main()
{
Window::Resize(720, 720);
Graphics::SetBackground(Palette::Black);
// 分割数
const int N_VTX = 48;
// 円の頂点
Array<Vec2> vtxCircle;
for (int i : step(N_VTX))
{
vtxCircle.emplace_back(90.0 * cos(TwoPi * i / N_VTX - QuarterPi), 90.0 * sin(TwoPi * i / N_VTX - QuarterPi));
}
// 長方形の頂点
Array<Vec2> vtxRect;
for (int i : step(N_VTX / 4)) { vtxRect.emplace_back(100.0, -100.0 + 200.0 * i / (N_VTX / 4)); }
for (int i : step(N_VTX / 4)) { vtxRect.emplace_back(100.0 - 200.0 * i / (N_VTX / 4), 100.0); }
for (int i : step(N_VTX / 4)) { vtxRect.emplace_back(-100.0, 100.0 - 200.0 * i / (N_VTX / 4)); }
for (int i : step(N_VTX / 4)) { vtxRect.emplace_back(-100.0 + 200.0 * i / (N_VTX / 4), -100.0); }
// モーフィング中の頂点
Array<Vec2> vtxMorph(N_VTX);
Array<Vec2> vtxMorph2(N_VTX);
while (System::Update())
{
const double F = static_cast<double>(System::FrameCount());
const double t = Clamp(Sin(F * 0.075) * 0.5 + 0.5, 0.0, 1.0);
const double easing = EaseInOut(Easing::Quad, t);
for (int i : step(N_VTX))
{
vtxMorphi = vtxCirclei * (1.0 - easing) + vtxRecti * easing; vtxMorph2i = vtxRecti * (1.0 - easing) + vtxCirclei * easing; }
Polygon(vtxMorph).rotated(F * 0.01).scale(2.0).moveBy(Window::Center()).draw(HSV(F * 0.3 + 45 * easing));
Polygon(vtxMorph2).rotated(-F * 0.03).moveBy(Window::Center()).draw(Palette::Black);
}
}